package cn.edu.scau.dormitory_management_system.module.examine.service.impl;

import cn.edu.scau.dormitory_management_system.enums.ApplicationStatusEnum;
import cn.edu.scau.dormitory_management_system.module.examine.dao.CheckoutApplicationDao;
import cn.edu.scau.dormitory_management_system.module.examine.entity.CheckoutApplicationEntity;
import cn.edu.scau.dormitory_management_system.module.examine.entity.VO.CheckoutApplicationVO;
import cn.edu.scau.dormitory_management_system.module.examine.service.CheckoutApplicationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author ：Vizzk
 * @description：TODO
 * @date ：2021/8/19 15:13
 */
@Service("checkoutApplicationService")
public class CheckoutApplicationServiceImpl extends ServiceImpl<CheckoutApplicationDao, CheckoutApplicationEntity> implements CheckoutApplicationService {
    @Override
    public boolean insertCheckoutApplication(CheckoutApplicationEntity application) {
        return this.baseMapper.insert(application)>0;
    }
    @Override
    public IPage<CheckoutApplicationVO> listCheckoutApplicationsByUserId(Integer userId, Integer pageNum, Integer pageSize) {
        Page<CheckoutApplicationVO> page = new Page<>(pageNum,10);
        IPage<CheckoutApplicationVO> pages = this.baseMapper.listCheckoutApplicationByUserId(page,userId);
        pages.getRecords().forEach(checkoutApplicationVO -> {
            checkoutApplicationVO.setStatusDescription(ApplicationStatusEnum.getRemarkByStatus(checkoutApplicationVO.getStatus()));
        });
        return pages;
    }


    @Override
    public IPage<CheckoutApplicationVO> listCheckoutApplications(Integer status, Integer deptId, String name, Integer pageNum, Integer pageSize) {
        Page<CheckoutApplicationVO> page = new Page<>(pageNum,pageSize);
        IPage<CheckoutApplicationVO> pages = this.baseMapper.listCheckoutApplications(page,status,deptId,name);
        pages.getRecords().forEach(checkoutApplicationVO -> {
            checkoutApplicationVO.setStatusDescription(ApplicationStatusEnum.getRemarkByStatus(checkoutApplicationVO.getStatus()));
        });
        return pages;
    }

    @Override
    public boolean retreatApplication(Integer id) {
        return this.baseMapper.retreatApplication(id);
    }
}
